package com.web.pojo.dto;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @Author: wws
 * describe:
 */

public class SetSwitchScheduleDTO implements Serializable {
    private Integer id; //设备id
    private byte channel;//通道 1 or 2
    private List<ScheduleDTO> schedule;

    public SetSwitchScheduleDTO() {
    }

    public SetSwitchScheduleDTO(Integer id,byte[] data) {
        this.id = id;
        this.channel = data[5];
        this.schedule = list(Arrays.copyOfRange(data,6,data.length));

    }


    public SetSwitchScheduleDTO(Integer id, byte channel, List<ScheduleDTO> schedule) {
        this.id = id;
        this.channel = channel;
        this.schedule = schedule;
    }

    private List<ScheduleDTO> list(byte[] bytes){
        System.out.println(Arrays.toString(bytes));
        List<ScheduleDTO> list = new ArrayList<>();

        for (int i =0;i<bytes.length;i+=4){

            byte[] bytes1 = Arrays.copyOfRange(bytes, i, i+4);
            ScheduleDTO scheduleDTO = new ScheduleDTO(bytes1);
            list.add(scheduleDTO);
        }
        return list;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public byte getChannel() {
        return channel;
    }

    public void setChannel(byte channel) {
        this.channel = channel;
    }

    public List<ScheduleDTO> getSchedule() {
        return schedule;
    }

    public void setSchedule(List<ScheduleDTO> schedule) {
        this.schedule = schedule;
    }

    @Override
    public String toString() {
        return "SetSwitchScheduleDTO{" +
                "id=" + id +
                ", channel=" + channel +
                ", schedule=" + schedule +
                '}';
    }
}
